<?php
/**
 * Login_Data_Checkuseremail
 * check user email into database
 *
 * @author adrian
 */
class Login_Data_Checkuseremail implements Login_Data_Mainable, Login_Data_Preparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type database query
     * database query handler
     */
    public $database_query;
    /**
     * constructor()
     */
    public function __construct(){
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * select user data
     * 
     * @param array $variables
     * @return type $users_data
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $users_data = $this->database->fetch('array');
        //var_dump($variables);
        //var_dump($users_data);
        //echo $this->database_query;
        //die();
        return $users_data;
    }

    /**
     * prepare_query()
     * prepare database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
       $this->database_query = "SELECT "
               . "user_name"
               . " FROM "
               . "users_data"
               . " WHERE "
               . "user_email='"
               .$variables['user_email'].
               "';"; 
    }

}
